package interface_;

/**
 * @Package: interface_
 * @ClassName: ExtendsVsInterface
 * @Author: x2606
 * @CreateTime: 2022/3/12 10:20
 * @Description:  继承和接口
 */

public class ExtendsVsInterface {
    public static void main(String[] args) {
        LittleMonkey littleMonkey = new LittleMonkey("littleMonkey");
        littleMonkey.climb();
        littleMonkey.swimming();
        littleMonkey.flying();
    }
}

class Monkey{
    String name;

    public Monkey(String name) {
        this.name = name;
    }

    public  void climb(){
        System.out.println(getName()+"爬树");
    }

    public String getName() {
        return name;
    }
}

interface Fish {
    public void swimming();
}

interface Bird{
    public void flying();
}

//当子类继承父类，自动用于父类功能
//当子类需要扩展功能时，可以通过实现接口来扩展功能
//可以理解，实现接口时对java单继承的一种补充
class LittleMonkey extends Monkey implements Fish,Bird{
    public LittleMonkey(String name) {
        super(name);
    }

    @Override
    public void swimming() {
        System.out.println(getName()+"通过学习，学会了游泳");
    }

    @Override
    public void flying() {
        System.out.println(getName()+"通过学习，学会了飞翔");
    }
}
